from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        CREATE TABLE IF NOT EXISTS `user` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `username` VARCHAR(12) NOT NULL UNIQUE COMMENT '用户名',
    `role` SMALLINT NOT NULL COMMENT '用户角色' DEFAULT 3,
    `phone` VARCHAR(11) UNIQUE COMMENT '手机号',
    `email` VARCHAR(50) NOT NULL UNIQUE COMMENT '邮箱',
    `password` VARCHAR(100) NOT NULL COMMENT '密码',
    `gender` VARCHAR(2) COMMENT '性别',
    `real_name` VARCHAR(50) COMMENT '真实名称',
    `is_active` BOOL NOT NULL COMMENT '用户状态' DEFAULT 1,
    `avatar` VARCHAR(255) COMMENT '头像图片存储地址',
    `created_at` DATETIME(6) NOT NULL COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL COMMENT '更新时间' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)
) CHARACTER SET utf8mb4 COMMENT='用户模型';
CREATE TABLE IF NOT EXISTS `jobs` (
    `job_id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `job_name` VARCHAR(255) NOT NULL COMMENT '工作名称',
    `company` VARCHAR(255) NOT NULL COMMENT '公司名称',
    `company_size` INT NOT NULL COMMENT '企业规模（员工数）',
    `salary` DECIMAL(10,2) NOT NULL COMMENT '薪资',
    `head` VARCHAR(50) NOT NULL COMMENT '负责人',
    `company_address` LONGTEXT NOT NULL COMMENT '企业地址',
    `company_industry` VARCHAR(100) NOT NULL COMMENT '企业所属行业',
    `company_email` VARCHAR(100) NOT NULL COMMENT '企业邮箱',
    `created_at` DATETIME(6) NOT NULL COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL COMMENT '更新时间' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `creator_id` INT NOT NULL COMMENT '创建人',
    CONSTRAINT `fk_jobs_user_c219d235` FOREIGN KEY (`creator_id`) REFERENCES `user` (`id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4 COMMENT='工作表';
CREATE TABLE IF NOT EXISTS `user_resumes` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `resume_url` VARCHAR(255) NOT NULL COMMENT '简历存储地址',
    `created_at` DATETIME(6) NOT NULL COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL COMMENT '更新时间' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `user_id` INT NOT NULL COMMENT '关联用户',
    CONSTRAINT `fk_user_res_user_110e3f7c` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4 COMMENT='用户简历存储表';
CREATE TABLE IF NOT EXISTS `aerich` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `version` VARCHAR(255) NOT NULL,
    `app` VARCHAR(100) NOT NULL,
    `content` JSON NOT NULL
) CHARACTER SET utf8mb4;"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        """
